package com.cate.controller.admin;

import com.cate.pojo.dto.DataTimeDTO;
import com.cate.pojo.vo.OrderReportVO;
import com.cate.pojo.vo.SalesTop10ReportVO;
import com.cate.pojo.vo.TurnoverReportVO;
import com.cate.pojo.vo.UserReportVO;
import com.cate.result.RestResponse;
import com.cate.service.ReportService;
import com.cate.utils.ResultUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;

/**
 * @CreateTime: 2023/8/2
 * @Author: <==lhd==>
 * @Description:
 */

@RestController
@Slf4j
@RequestMapping("/admin/report")
@Api(tags = "数据统计管理")
public class ReportController {

    @Autowired
    private ReportService reportService;

    @GetMapping("/userStatistics")
    @ApiOperation("用户统计接口")
    public RestResponse<Object> userStatistics(DataTimeDTO timeDTO){
        final UserReportVO userStatistics = reportService.getUserStatistics(timeDTO.getBegin(), timeDTO.getEnd());
        return ResultUtil.success(userStatistics);
    }

    @GetMapping("/ordersStatistics")
    @ApiOperation("订单统计接口")
    public RestResponse<OrderReportVO> ordersStatistics(DataTimeDTO timeDTO){
        final OrderReportVO orderStatistics = reportService.getOrderStatistics(timeDTO.getBegin(), timeDTO.getEnd());
        return ResultUtil.success(orderStatistics);
    }

    @GetMapping("/top10")
    @ApiOperation("查询销量排名top10接口")
    public RestResponse<SalesTop10ReportVO> getTop10(DataTimeDTO timeDTO){
        final SalesTop10ReportVO salesTop10 = reportService.getSalesTop10(timeDTO.getBegin(), timeDTO.getEnd());
        log.info("salesTop10={}",salesTop10);
        return ResultUtil.success(salesTop10);
    }

    @GetMapping("/turnoverStatistics")
    @ApiOperation("营业额统计接口")
    public RestResponse<TurnoverReportVO> turnoverStatistics(DataTimeDTO timeDTO){
        final TurnoverReportVO reportVO = reportService.getTurnoverStatistics(timeDTO.getBegin(), timeDTO.getEnd());
        return ResultUtil.success(reportVO);
    }

    @GetMapping("/export")
    @ApiOperation("导出Excel报表")
    public void exportExcel(HttpServletResponse httpServletResponse){
        reportService.exportBusinessData(httpServletResponse);
    }

}
